home *** CD-ROM | disk | FTP | other *** search
/ Gekikoh Dennoh Club 1 / Gekikoh Dennoh Club Vol. 1 (Japan).7z / Gekikoh Dennoh Club Vol. 1 (Japan) (Track 1).bin / tools / ebsx130 / ebgraph.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-05  |  10.6 KB  |  463 lines

  1. /*
  2.  * lib Method SX : skelton
  3.  *
  4.  *  Author : D.N  kit.iizuka
  5.  *  Created: 1994  1/12(Wed)
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <method\Task_i.h>
  10. #include <method\Dialog_i.h>
  11. #include <method\Memory_i.h>
  12. #include <method\Graph_i.h>
  13. #include <method/Window_i.h>
  14. #include <method\methodSx.h>
  15. #include <method\Dos_i.h>
  16. #include <method\sxutil.h>
  17.  
  18. #define SXVERSION 0x300 /* SXのバージョンチェックをしない場合は外す */
  19.  
  20. #define MAIN_DX 256  /* メインウインドウの横幅 */
  21. #define MAIN_DY 200  /* メインウインドウの縦幅 */
  22. #define MAIN_ID 32   /* メインウインドウの種類 */
  23. #define MAIN_OPT 0   /* メインウインドウの付属品 */
  24.  
  25. /*
  26.  * 関数宣言
  27.  */
  28. int MainDraw();
  29.  
  30. unsigned int    conv_hex( unsigned int );
  31. int        showgraph( unsigned short , unsigned short , unsigned int );
  32. int        search_graphicindex( unsigned int );
  33. int        MultiMouse(void);
  34. int        DispPrev( void );
  35. int        DispNext( void );
  36.  
  37.  
  38. int        cdfile;
  39. rectImg        *ri;            /* レクタングルイメージへのポインタ */
  40. unsigned short    gra_x = 256;        /* kenji suzuki  */
  41. unsigned short    gra_y = 200;        /* kenji suzuki  */
  42.  
  43. unsigned int    cur_seekptr = 0;    /* 現在のインデックスのファイルポインタ先頭 */
  44. unsigned int    nex_seekptr = 0;    /* 1つ後のインデックスのファイルポインタ先頭 */
  45.  
  46. unsigned int    rirekitbl[ 258 ];    /* 履歴テーブル */
  47. int        rirekimax;
  48.  
  49. char        e_key = 0;        /* EPWINGタイプなら=1 */
  50.  
  51. /*
  52.  * 描画ルーチンリスト
  53.  */
  54. proc_list_t
  55.     mainDraw = {MainDraw, NULL /* リスト終了 */};
  56.  
  57. /*
  58.  * ウインドウ定義
  59.  */
  60. window_t mainWin = {
  61.     &mainDraw, (window *) NULL, (window *) -1, {0, 0, MAIN_DX, MAIN_DY},
  62.     "\@Untitled", 0, (MAIN_ID << 4) + MAIN_OPT, 0b0001
  63. };
  64.  
  65.  
  66. /*
  67.  * 各種Methodの内容定義
  68.  */
  69. /*
  70. m__t
  71. */
  72. m_control_t    cprev = {{0 , 0, 0  + 6*6 + X_STDBTN, 0 + DY_STDBTN}, 0, 0, 1, 0, "\@▲"},
  73.         cnext  = {{48, 0, 48 + 6*6 + X_STDBTN, 0 + DY_STDBTN}, 0, 0, 1, 0, "\@▼"};
  74.  
  75. /*
  76.  * Method, Method Group定義
  77.  */
  78. method_t
  79.     mNext = {NULL, m_STDBTN, &cnext, DispNext},
  80.     mPrev = {NULL, m_STDBTN, &cprev, DispPrev},
  81.     *methods[] = {&mNext , &mPrev , NULL};
  82.  
  83. /*
  84.  * Jobの定義
  85.  */
  86. /*
  87.  job_t
  88. */    
  89.  
  90. /*
  91.    グラフィックインデックス内のサーチ 
  92.    1f32~1f52の後に続く6バイトは、次のインデックスへリンクするポインタ
  93.    1f33~1f63の後に続く8バイトは、意味が判らない というわけで、何もしない
  94.    1f42~1f62の後に続く6バイトは、意味が判らない というわけで、何もしない
  95. */
  96. /* int    search_graphicindex( unsigned int page , unsigned int offset ) */
  97. int    search_graphicindex( unsigned int filepos )
  98. {
  99.     unsigned short    c , flg;
  100.     unsigned int    indexpage , indexoff;
  101.     long    position;
  102.  
  103.     DOSSEEK( cdfile , filepos, SEEK_SET );
  104.  
  105. /*    DOSREAD( cdfile , &c , sizeof( unsigned short ) ); */
  106. /*    if( (c&0xffff) == 0x1f09 )
  107.     {
  108.         DOSREAD( cdfile , &c , sizeof( unsigned short ) );
  109.     } else {
  110.         DOSSEEK( cdfile , -2 , SEEK_CUR );
  111.     };
  112. */
  113.     position = filepos;
  114.     flg = 0;
  115.     for (;;) {
  116.         DOSREAD( cdfile , &c , sizeof( unsigned short ) );
  117.         position+=2;
  118.         if ((c&0xff00)==0x1f00) {
  119.             switch (c&0xff) {
  120.                 case 0x45:
  121.                     DOSREAD( cdfile , &c , sizeof( unsigned short ) );
  122.                     position+=2;
  123.                     break;
  124.                 case 0x65:
  125.                     return( 0 );
  126.                 case 0x42:
  127.                     DOSREAD( cdfile , &c     , sizeof( unsigned short ) );
  128.                     DOSREAD( cdfile , &c     , sizeof( unsigned short ) );
  129.                     position+=4;
  130.                     break;
  131.                 case 0x62:
  132.                     DOSREAD( cdfile , &c     , sizeof( unsigned short ) );
  133.                     DOSREAD( cdfile , &c     , sizeof( unsigned short ) );
  134.                     DOSREAD( cdfile , &c     , sizeof( unsigned short ) );
  135.                     position+=6;
  136.                     break;
  137.  
  138.                 case 0x31:
  139.                     /* グラフィック用画面のサイズ? */
  140.                     DOSREAD( cdfile , &c     , sizeof( unsigned short ) );
  141.                     DOSREAD( cdfile , &gra_x , sizeof( unsigned short ) );
  142.                     DOSREAD( cdfile , &gra_y , sizeof( unsigned short ) );
  143.                     gra_x = conv_hex( gra_x );
  144.                     gra_y = conv_hex( gra_y );
  145.                     position+=6;
  146.                     break;
  147.                 case 0x51:
  148.                     /*  */
  149.                     DOSREAD( cdfile , &indexpage , sizeof( unsigned int ) );
  150.                     DOSREAD( cdfile , &c         , sizeof( unsigned short ) );
  151.                     indexoff = (int)c;
  152.                     position+=6;
  153.                     indexpage = conv_hex( indexpage );
  154.                     indexoff = conv_hex( indexoff );
  155.  
  156.                     showgraph( gra_x , gra_y , (indexpage-1)*0x800+indexoff );
  157.                     DOSSEEK( cdfile , position , SEEK_SET );    /* ファイルポインタを元に戻す */
  158.                     break;
  159.                 case 0x32:
  160.                     /* テキスト用画面のサイズ? */
  161.                     DOSREAD( cdfile , &c     , sizeof( unsigned short ) );
  162.                     DOSREAD( cdfile , &c     , sizeof( unsigned short ) );
  163.                     position+=4;
  164.                     break;
  165.                 case 0x52:
  166.                     /* 次へのポインタ */
  167.                     DOSREAD( cdfile , &indexpage , sizeof( unsigned int   ) );
  168.                     DOSREAD( cdfile , &c         , sizeof( unsigned short ) );
  169.                     indexoff = (int)c;
  170.                     indexpage = conv_hex( indexpage );
  171.                     indexoff = conv_hex( indexoff );
  172.                     nex_seekptr = (indexpage-1)*0x800+indexoff;
  173.                     position += 6;
  174.                     break;
  175.                 case 0x33:
  176.                     DOSREAD( cdfile , &c , sizeof( unsigned short ) );
  177.                     DOSREAD( cdfile ,  &c , sizeof( unsigned short ) );
  178.                     position+=4;
  179.                     break;
  180.                 case 0x53:
  181.                     DOSREAD( cdfile , &c     , sizeof( unsigned short ) );
  182.                     DOSREAD( cdfile , &c     , sizeof( unsigned short ) );
  183.                     DOSREAD( cdfile , &c     , sizeof( unsigned short ) );
  184.                     DOSREAD( cdfile , &c     , sizeof( unsigned short ) );
  185.                     position+=8;
  186.                     break;
  187.                 case 0x34:
  188.                     break;
  189.                 case 0x54:
  190.                     break;
  191.                 default:
  192.                     break;
  193.             }
  194.         }
  195.     }
  196. }
  197.  
  198. /* グラフィックイメージの表示 */
  199. int    showgraph( unsigned short x , unsigned short y  , unsigned int filepos )
  200. {
  201.     ri = (rectImg *)_ULMALLOC( ((x/8)*y*2)+32 );    /* イメージを格納するメモリの確保 64byte余裕をもたせた */
  202.     if( ri == NULL )
  203.     {
  204.         return( -1 );
  205.     };
  206. /* printf( "graph = %x %x\n" , page , offset ); */
  207.     /* レクタングルイメージの第1ページ、第2ページにデータをセット(黒で表示) */
  208.     DOSSEEK( cdfile , filepos , SEEK_SET );
  209.     DOSREAD( cdfile , &(*ri).data , (x/8)*y );
  210.  
  211.     memcpy( &((*ri).data)+(x/8*y) , &(*ri).data , (x/8)*y );
  212.  
  213.     (*ri).bounds.top = 0;
  214.     (*ri).bounds.left = 0;
  215.     (*ri).bounds.right = x;
  216.     (*ri).bounds.bottom = y;
  217.  
  218.     return( 0 );
  219. }
  220.  
  221. /* BCDコードを16進に変換 */
  222. unsigned int    conv_hex( unsigned int data )
  223. {
  224.     unsigned int    data16;
  225.     unsigned char    hhh,hhl,hlh,hll;
  226.     unsigned char    lhh,lhl,llh,lll;
  227.  
  228.     data16 = 0;
  229.  
  230.     hhh = (data & 0xf0000000) >> 28;
  231.     hhl = (data & 0x0f000000) >> 24;
  232.     hlh = (data & 0x00f00000) >> 20;
  233.     hll = (data & 0x000f0000) >> 16;
  234.     lhh = (data & 0x0000f000) >> 12;
  235.     lhl = (data & 0x00000f00) >> 8;
  236.     llh = (data & 0x000000f0) >> 4;
  237.     lll = (data & 0x0000000f);
  238.  
  239.     data16 = hhh*10000000 + hhl*1000000 + hlh*100000 + hll*10000;
  240.     data16 = data16 + lhh*1000 + lhl*100 + llh*10 + lll;
  241.  
  242.     return( data16 );
  243. }
  244.  
  245. /* 履歴テーブル関係 */
  246. int    init_rirekitbl( void )
  247. {
  248.     rirekitbl[ 0 ] = 0;
  249.     rirekimax = 0;
  250.  
  251.     return( 0 );
  252. };
  253.  
  254. int    push_rireki( int rireki )
  255. {
  256.     if( rirekimax == 256 )
  257.     {
  258.         return( -1 );
  259.     };
  260.  
  261.     rirekimax++;
  262.     rirekitbl[ rirekimax ] = rireki;
  263.     rirekitbl[ rirekimax+1 ] = 0;
  264.  
  265.     return( 0 );
  266. };
  267.  
  268. /*
  269.  * 描画関数定義
  270.  */
  271. int MainDraw()
  272. {
  273.     rect winside;
  274.     point_t wsize;
  275.  
  276.     if( nex_seekptr != 0 )
  277.     {
  278.         AwakeMethod( &mNext , 1 );
  279.     } else {
  280.         SleepMethod( &mNext , 1 );
  281.     };
  282.     if( rirekimax > 1 )
  283.     {
  284.         AwakeMethod( &mPrev , 1 );
  285.     } else {
  286.         SleepMethod( &mPrev , 1 );
  287.     };
  288.  
  289.     GetWinInside(&mainWin, &winside);
  290.     wsize = ULSizeOfRect(&winside);
  291.     ULD3LineH(Point_t(0, 20), Point_t(Pt_x(wsize), 0), 1);
  292.     if( ri != NULL )
  293.     {
  294.         /* アクセスページセット */
  295.         GMAPage (0b0011);
  296.  
  297.         GMPutRImg( ri , 21 );
  298.     };
  299.  
  300.     return 0;
  301. }
  302.  
  303.  
  304. /* tsugi */
  305. int DispNext()
  306. {
  307.     if( nex_seekptr != 0 )
  308.     {
  309.         if(( rirekimax > 0 ) && ( rirekimax <= 256 ))
  310.         {
  311.             push_rireki( nex_seekptr );
  312.             cur_seekptr = nex_seekptr;
  313.             nex_seekptr = 0;
  314.             search_graphicindex( cur_seekptr );
  315.             MainDraw( );
  316. /*        } else {
  317.             DMError( 1,"これより後方の画像は表示できません\n" );
  318. */        };
  319.     };
  320.  
  321.     return( 1 );
  322. }
  323.  
  324. /* mae */
  325. int DispPrev()
  326. {
  327.     if( rirekimax > 1 )
  328.     {
  329.         cur_seekptr = rirekitbl[ rirekimax-1 ];
  330.         rirekimax -= 1;
  331.         nex_seekptr = 0;
  332.         search_graphicindex( cur_seekptr );
  333.         MainDraw( );
  334. /*    } else {
  335.         DMError( 1,"これより後方の画像は表示できません\n" );
  336. */    };
  337.  
  338.     return( 1 );
  339. }
  340.  
  341.  
  342. void MainLoop()
  343. {
  344.     order_t order = {0};
  345.     while (true) {
  346.         order.ev = MayIHelpYou();
  347.         switch (order.ev) {
  348.           case EV_CLOSEALL:
  349.           case EV_CLOSEWIN:
  350.             return;                /* 終了指令ならメインループ終了 */
  351.           case EV_SAVE:            /* 終了するのでセーブしなくてはいけない */
  352.           case EV_ACTIVATE:        /* アクティベイト event が起こった */
  353.           case EV_OPENFILE:        /* ファイルが開かれた */
  354.           case EV_CLOSEFILE:    /* ファイルクローズ */
  355.           case EV_DELETEFILE:    /* ファイルの削除 */
  356.           case EV_CREATETSK:    /* あるタスクの開始 */
  357.           case EV_EXITTSK:        /* あるタスクの終了 */
  358.           case EV_UNDEFINED:    /* 上で定義されていないSYSTEM12 event */
  359.             continue;            /* 無視する物は明示しておいた方が効率が良い? */
  360.           default:
  361.             ; /* ここでMethodの判定をする */
  362.         }
  363.     }
  364. }
  365.  
  366. int main( int ac , char *av[] )
  367. {
  368.     int i;
  369.     char    *ptr;
  370.     unsigned int seekptr = 0;
  371.     char    *wintitle = NULL;
  372.     char    work[ 40 ];
  373.     int    linkflg;
  374.  
  375.     if( ac < 2 )
  376.     {
  377.         return( 0 );
  378.     };
  379.  
  380.     /* コマンドラインオプションの読み取り */
  381.     for (i = 1; i < ac; i++) {
  382.         ptr = av[i];
  383.         switch (*ptr) {
  384.           case '/':
  385.           case '-':
  386.             ptr++;
  387.             if ('t' == *ptr )
  388.             {
  389.                 ptr++;
  390.                 seekptr = ULSTOX( ptr );
  391.                 cur_seekptr = seekptr;
  392.             } else if ('f' == *ptr )
  393.             {
  394.                 ptr++;
  395.                 cdfile = TSOpen( ptr , 0 );
  396.                 if( cdfile < 0 )
  397.                 {
  398.             /*        ULError_str( "Error ファイルがオープンできません path=\n" , ptr );
  399.             */        return( 0 );
  400.                 };
  401.             } else if ('n' == *ptr )
  402.             {
  403.                 ptr++;
  404.                 wintitle = ptr;
  405.             } else if ('e' == *ptr )
  406.             {
  407.                 e_key = 1;
  408.             } else if ('x' == *ptr )
  409.             {
  410.                 ptr++;
  411.                 gra_x = ULSTOX( ptr );
  412.             } else if ('y' == *ptr )
  413.             {
  414.                 ptr++;
  415.                 gra_y = ULSTOX( ptr );
  416.             };
  417.             break;
  418.         }
  419.     }
  420. /*    DOSSEEK( cdfile , seekptr , SEEK_SET ); */
  421.  
  422.     if( e_key == 1 )
  423.     {
  424.         showgraph( gra_x , gra_y , seekptr );
  425.     } else {
  426.         search_graphicindex( seekptr );
  427.     };
  428.  
  429.     mainWin.bound.right = gra_x;
  430.     mainWin.bound.bottom = gra_y+21;
  431.  
  432.     if (OpenWindow(&mainWin, -1) < 0) {
  433.         DMError( 1, "ウインドウさえ開きません" );
  434.         _ULFREE( ri );
  435.         TSClose( cdfile );
  436.         return 1;
  437.     };                        /* ウインドウを開く */
  438.  
  439.     ChainMethodIn(&mainWin, methods);            /* Methodを登録する */
  440.  
  441.     init_rirekitbl( );
  442.     push_rireki( seekptr );
  443.  
  444.     if( wintitle != NULL )
  445.     {
  446.         strcpy( work , "画像 [" );
  447.         strcat( work , wintitle );
  448.         strcat( work , "]" );
  449.         ULStrZTOLZ( work );        /* LASCIIを作る */
  450.         WMTitleSet( mainWin.wptr , work );
  451.     };
  452.     MainLoop();                            /* メインループ */
  453.     UnchainMethod();                    /* Methodを登録から外す */
  454.     CloseWindow(&mainWin);                /* ウインドウを閉じる */
  455.     _ULFREE( ri );
  456.     if( cdfile != 0 )
  457.     {
  458.         TSClose( cdfile );
  459.     };
  460.  
  461.     return( 0 );
  462. }
  463.